package com.ruoyi.edu.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.constant.HttpStatus;
import com.ruoyi.edu.api.domain.vo.EduCommentVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.edu.api.domain.EduComment;
import com.ruoyi.edu.service.IEduCommentService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 评论Controller
 *
 * @author ruoyi
 * @date 2023-09-18
 */
@RestController
@RequestMapping("/comment")
public class EduCommentController extends BaseController {
    @Autowired
    private IEduCommentService eduCommentService;

    /**
     * 查询评论列表
     */
    @RequiresPermissions("edu:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(EduComment eduComment, Integer pageNum, Integer pageSize) {
        // 返回VO方法，分页方法自己写
        List<EduCommentVO> list = eduCommentService.selectEduCommentList(eduComment);
        return getDataTableVO(list, pageNum, pageSize);
    }

    /**
     * 导出评论列表
     */
    @RequiresPermissions("edu:comment:export")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EduComment eduComment) {
        List<EduCommentVO> list = eduCommentService.selectEduCommentList(eduComment);
        ExcelUtil<EduCommentVO> util = new ExcelUtil<>(EduCommentVO.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @RequiresPermissions("edu:comment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(eduCommentService.selectEduCommentById(id));
    }


    /**
     * 删除评论
     */
    @RequiresPermissions("edu:comment:remove")
    @Log(title = "评论", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(eduCommentService.deleteEduCommentByIds(ids));
    }
}
